package database;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import entity.Student_Info;

public class LinkTest {
	public static void main(String[] args) {
		try {
			Class.forName("oracle.jdbc.driver.OracleDriver");
			System.out.println("driver loaded!");
			
			Connection conn=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","manager","manager");
			System.out.println("connected!");
			
			Statement stm=conn.createStatement();
			
			ResultSet rs=stm.executeQuery("select * from student_info");
			
			List<Student_Info> list=new ArrayList<>();
			
			while(rs.next()){
				//System.out.println(rs.getInt("ID") + "\t" + rs.getString("name") + "\t" + rs.getString("gender"));
				Student_Info stuinfo=new Student_Info();
				stuinfo.setId(rs.getInt("id"));
				stuinfo.setName(rs.getString("name"));
				stuinfo.setGender(rs.getString("gender"));
				list.add(stuinfo);
			}
			
			for (Student_Info stuinfo : list) {
				System.out.println(stuinfo.getId() + "\t" + stuinfo.getName() + "\t" + stuinfo.getGender());
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
